﻿// ***********************************************************************
// Assembly         : STX.Admin
// Author           : seven.x
// Created          : 02-28-2014
//
// Last Modified By : seven.x
// Last Modified On : 02-28-2014
// ***********************************************************************
// <copyright file="Cost.aspx.cs" company="驰创数码">
//     Copyright (c) 驰创数码. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Reporting.WebForms;
using STX.Domain;
using STX.Repository;

namespace STX.Admin.Export
{
    /// <summary>
    /// Class Cost.
    /// </summary>
    public partial class Cost : System.Web.UI.Page
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id= 6;
                int.TryParse(Request["id"], out id);
                GenerateReport(id);
            }
        }

        /// <summary>
        /// Generates the report.
        /// </summary>
        /// <param name="id">The unique identifier.</param>
        private void GenerateReport(int id)
        {
            var transaction = new EfTransactionContext();
            var activity = transaction.GetRepository<STX.Domain.BizActivity>().FindAll().FirstOrDefault(o => o.Id == id);
            if(activity==null) return;

            this.ReportViewer1.LocalReport.ReportPath
                = Server.MapPath("~/Administrator/Export/ReportViewerTemplates/Cost.rdlc");
            //var list = (from s in new STX.Service.BUS_MainService().FindAll()
            //            where s.date_out.Year == dt.Year && s.date_out.Month == dt.Month && s.date_out.Day == dt.Day
            //            select s).ToList();
            ReportDataSource datasource = new ReportDataSource("DataSet1", activity.BizActivityItems);

            var rp = new ReportParameter("ActivityName", activity.Name);
            var rp1 = new ReportParameter("ProjectName", activity.BizProject.Name);
            var rp2 = new ReportParameter("ActivityPlace", activity.Place);
            var rp3 = new ReportParameter("ActivityStartTime", activity.StartTime.ToString("yyyy.MM.dd"));
            var rp4 = new ReportParameter("ActivityEndTime", activity.EndTime.ToString("yyyy.MM.dd"));
            var rp5 = new ReportParameter("ResponsiblePerson", activity.ResponsiblePerson);
            var rp6 = new ReportParameter("QuotationTabulator", activity.QuotationTabulator);
            var rp7 = new ReportParameter("QuotationGeneratedTime", activity.QuotationGeneratedTime.ToString("yyyy.MM.dd"));
            var rp8 = new ReportParameter("TimeDetail", activity.TimeDetail);
            var rp9 = new ReportParameter("CompanyName", STX.Lib.Utils.STXConfig.GetValue("/config/custom/companyName"));
            var rp10 = new ReportParameter("CostTabulator", activity.CostTabulator);
            var rp11 = new ReportParameter("CostGeneratedTime", activity.CostGeneratedTime.ToString("yyyy.MM.dd"));
            var rp12 = new ReportParameter("Executor", activity.Executor);
            var rp13 = new ReportParameter("Planner", activity.Planner);
            var rp14 = new ReportParameter("Driver", activity.Driver);
            this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] {rp, rp1, rp2, rp3, rp4, rp5, rp6,rp7,rp8,rp9});

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.DataSources.Add(datasource);
        }

        
    }
}